﻿using Extension.Utilities;
using PatcherYRpp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;

namespace Extension.Ext
{
    public partial class TechnoExt
    {
        public string MyExtensionTest = nameof(MyExtensionTest);

        public unsafe void OnInit()
        {
            TechnoClass_Init_Convert_Unload();
            //TechnoClass_Init_Virtual_Turret();
        }

        public unsafe void OnUpdate()
        {
            TechnoClass_Update_Fighter_Area_Guard();
            TechnoClass_Update_Convert_Unload();
            TechnoClass_Update_Virtual_Turret();
            TechnoClass_Update_Passenger_Extension();
            TechnoClass_Passenger_InTransport_Extension();
            TechnoClass_AttachEffectScript_Update();
        }

        public unsafe void OnPut(CoordStruct coordStruct,Direction faceDir)
        {
            TechnoClass_AttachEffectScript_Put(coordStruct,faceDir);
            //TechnoClass_Debug_OnPut(coordStruct, faceDir);
        }

        public unsafe void OnRemove()
        {
            TechnoClass_AttachEffectScript_Remove();
            //TechnoClass_Init_Virtual_Turret();
        }

        public unsafe void OnFire(Pointer<AbstractClass> pTarget, int weaponIndex)
        {
            TechnoClass_AttachEffectScript_Fire(pTarget,weaponIndex);
            //TechnoClass_Debug_OnFire(pTarget, weaponIndex);
        }

        public unsafe void OnReceiveDamage(Pointer<int> pDamage, int DistanceFromEpicenter, Pointer<WarheadTypeClass> pWH,
         Pointer<ObjectClass> pAttacker, bool IgnoreDefenses, bool PreventPassengerEscape, Pointer<HouseClass> pAttackingHouse)
        {
            TechnoClass_AttachEffectScript_ReceiveDamage(pDamage, DistanceFromEpicenter, pWH, pAttacker, IgnoreDefenses, PreventPassengerEscape, pAttackingHouse);
            //TechnoClass_Debug_OnReceiveDamage(pDamage, DistanceFromEpicenter, pWH, pAttacker, IgnoreDefenses, PreventPassengerEscape, pAttackingHouse);
        }

    }

    public partial class TechnoTypeExt
    {
        public SwizzleablePointer<SuperWeaponTypeClass> FireSuperWeapon = new SwizzleablePointer<SuperWeaponTypeClass>(IntPtr.Zero);


        [INILoadAction]
        public void LoadINI(Pointer<CCINIClass> pINI)
        {
            INIReader reader = new INIReader(pINI);
            string section = OwnerObject.Ref.Base.Base.ID;

            reader.ReadSuperWeapon(section, nameof(FireSuperWeapon), ref FireSuperWeapon.Pointer);

            ReadFighterGuardData(reader,section);
            ReadScriptArgs(reader,section);
            ReadConvertUnloadData(reader, section);
            ReadCopyableData(reader, section);
            //ReadVirtualTurretData(reader, section);
            ReadCustomFlagData(reader, section);
            ReadPassengerExtensionData(reader, section);
        }

        [LoadAction]
        public void Load(IStream stream)
        {
        }
        [SaveAction]
        public void Save(IStream stream)
        {
        }
    }
}
